CustomerTableFactory   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 20
dl 0
loc 26
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A create 0 19 1
1
import { Injectable } from '@nestjs/common';
2
import { CustomerView } from 'src/Application/Customer/View/CustomerView';
3
import { RouteNameResolver } from 'src/Infrastructure/Common/ExtendedRouting/RouteNameResolver';
4
import { RowFactory } from 'src/Infrastructure/Tables/RowFactory';
5
import { Table } from 'src/Infrastructure/Tables';
6
7
@Injectable()
8
export class CustomerTableFactory {
9
  constructor(
10
    private readonly resolver: RouteNameResolver,
11
    private readonly rowFactory: RowFactory
12
  ) {}
13
14
  public create(customers: CustomerView[]): Table {
15
    const columns = ['crm-customers-name', 'common-actions'];
16
17
    const rows = customers.map(customer =>
18
      this.rowFactory
19
        .createBuilder()
20
        .value(customer.name)
21
        .actions({
22
          edit: {
23
            url: this.resolver.resolve('crm_customers_edit', {
24
              id: customer.id
25
            })
26
          }
27
        })
28
        .build()
29
    );
30
31
    return new Table(columns, rows);
32
  }
33
}
34